package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduCommentMapper;
import com.atguigu.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author 董万均
 * @since 2020-11-07
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public Map<String, Object> selectCommentPage(Page<EduComment> commentPage,String courseId) {
        QueryWrapper<EduComment> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create");//根据时间排序
        wrapper.eq("course_id",courseId);//查询当前课程所在的评论
        //将分页查询结果封装到teacherPage对象
        baseMapper.selectPage(commentPage, wrapper);//会将数据分页，并将分页后的数据封装到teacherPage里面
        List<EduComment> records = commentPage.getRecords();//每页记录数
        long current = commentPage.getCurrent();//当前页
        long pages = commentPage.getPages();//当前分页总页数
        long size = commentPage.getSize();//每页显示条数
        long total = commentPage.getTotal();//总的条数
        boolean hasNext = commentPage.hasNext();//下一页
        boolean hasPrevious = commentPage.hasPrevious();//上一页

        Map<String,Object> map=new HashMap<>();
        map.put("records",records);
        map.put("current",current);
        map.put("pages",pages);
        map.put("size",size);
        map.put("total",total);
        map.put("hasNext",hasNext);
        map.put("hasPrevious",hasPrevious);
        //将所有的结果都返回
        return map;
    }
}
